# 使用类实现迭代器，实现斐波拉契数列
# class Fbo():
#     def __init__(self,n):
#         #n 表示计算前ｎ项　用以判断迭代的条件
#         self.n = n
#         self.a = 0
#         self.b = 1
#         #C_number 用来记录访问多少项的位置
#         self.C_number = 0
#     def __iter__(self):
#         return self
#     def __next__(self):
#         if self.C_number < self.n:
#             num = self.a
#             self.a,self.b = self.b, self.b + self.a
#             self.C_number += 1
#             return num
#         else:
#             raise StopIteration
# fbo = Fbo(9)
# for i in fbo:
#     print(i)

# print(list(fbo))


#使用面向对象做一个ATM（存取款功能）
#ATM类
#  属性： 钱，区域
#  方法：（存取）
#      用户可以过来取钱
#      取了钱ATM的钱就会减少
#      用户的账户的钱也会减少
#用户类
#  属性：用户名，  密码， 账户金额
#要求：
#    菜单   有登陆验证
class ATM():
    money = 100000000
    def __init__(self,region):
        self.region = region
    def save(self,c_money):
        self.c_money = c_money
        self.money += c_money
        print(f"存了{c_money},ATM共有{self.money}")
    def draw_money(self,getmoney,c_money):
        if getmoney <= self.money:
            self.money -= getmoney
            print(f"取了{getmoney}，ATM还剩下{self.money}")
            if c_money >= getmoney:
                self.c_money -= getmoney
                print(f"取了{getmoney},{self.username}账户余额还剩下{self.c_money}")


class User(ATM):

    def __init__(self,username,passwd,u_money):
        self.username = username
        self.passwd = passwd
        self.u_money = u_money
    print(f"欢迎进入ATM系统".center(50, "*"))
    def login(self):
        print(f"欢迎进入登陆系统".center(50, "*"))
        user_dict = {"root": {"passwd": "123456", "u_money": 500000},
                     "admin": {"passwd": "admin", "u_moeny": 200000}
                     }
        self.username = input("请输入用户名：")
        self.passwd = input("请输入用户名密码:")
        if user_dict.get(self.username) and user_dict.get(self.username).get('passwd') == self.passwd:
            print(f"{self.username}登陆成功")
        else:
            print(f"{self.username}登陆失败")

    def register(self):
        print(f"注册用户".center(50, "*"))
        user_dict = {"root": {"passwd": "123456", "u_money": 500000},
                     "admin": {"passwd": "admin", "u_moeny": 200000}
                     }
        self.username = input("请输入用户名：")
        self.passwd = input("请输入用户名密码:")
        if self.username not in user_dict:
            user_dict[self.username] = {"passwd":self.passwd,"money":0}
            print("注册成功")
            user_dict.update({self.username:self.passwd})
        else:
            print("注册失败")


atm1 = ATM("湖南长沙")
# print(atm1)
user = User("root","123456",500000)
# print(user)
user.login()
user.save(500000)
user.draw_money(3000,500000)
user.register()
user1 = User("zhangsan","123456",9000000)
# print(user1)
user1.login()
user1.save(9000000)
user1.draw_money(1000000,9000000)










